package com.china08.yxyapi.api.manage.tec.teaching.lesson.cloud;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.cloud.YxyLessonsCloudCatalog;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.lesson.YxyLessonsCloudCatalogRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class TecLessonCatalogListController extends YxyApiBaseController {

    @Autowired
    YxyLessonsCloudCatalogRepository catalogRepository;

    @ApiOperation("")
    @RequestMapping(value = "/api_yw/manage/tec/teaching/lesson/cloud/catalog/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String pid = reqModel.pId;
        Integer leve = reqModel.leve;
        List<YxyLessonsCloudCatalog> catalogs = catalogRepository.findByPidOrderByOrderNumAscCreatedDateAsc(pid);
        List<Pojo> returnList = new ArrayList<Pojo>();
        Pojo pojo = new Pojo();
        pojo.id = "";
        if (leve == 1) {
            pojo.name = "全部一级";
        } else if (leve == 2) {
            pojo.name = "全部二级";
        } else if (leve == 3) {
            pojo.name = "全部三级";
        } else if (leve == 4) {
            pojo.name = "全部四级";
        } else if (leve == 5) {
            pojo.name = "全部五级";
        }
        returnList.add(pojo);
        for (YxyLessonsCloudCatalog catalog : catalogs) {
            pojo = new Pojo();
            pojo.id = catalog.getId();
            pojo.name = catalog.getName();
            returnList.add(pojo);
        }
        RespModel respModel = new RespModel();
        respModel.list = returnList;
        return respModel;
    }

    public static class Pojo {
        public String id;
        public String name;
    }

    public static class ReqModel extends YxyApiReqModel {
        public String pId;
        public Integer leve;
    }

    public static class RespModel extends YxyApiRespModel {
        public List<Pojo> list;
    }

}
